package com.xsky.logic.casehistory;

import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.xsky.common.util.UUIDUtil;
import com.xsky.common.util.XMLConverter;
import com.xsky.database.dao.impl.BaseEntityDaoImpl;
import com.xsky.operation.vo.TabCaseOperateHistory;

public class CaseOperateHistoryLogic {

	BaseEntityDaoImpl dao = new BaseEntityDaoImpl();

	public String addOrUpdateCaseOperateHistory(String xml) {
		TabCaseOperateHistory entity = XMLConverter.convertToObject(xml, TabCaseOperateHistory.class);
		if (StringUtils.isEmpty(entity.getId())) {
			entity.setId(UUIDUtil.getUUID());
		}
		entity.setTimestamp(new Date());
		dao.insertEntity(entity);
		return "<data><result>ok</result><uuid>" + entity.getId() + "</uuid><info>添加成功</info></data>";
	}

	@SuppressWarnings("unchecked")
	public List<TabCaseOperateHistory> queryHistoryByCaseId(String caseId) {
		return dao.findByKey(new TabCaseOperateHistory(), "caseId", caseId);
	}

	/**
	 * 根据caseid查询其所有操作历史，并以xml的方式返回
	 * @param caseId
	 * @return
	 */
	public String queryHistoryXML(String caseId) {
		return XMLConverter.convertToXML(queryHistoryByCaseId(caseId));
	}
}
